using System;
using System.Runtime.Remoting.Contexts;
using System.Runtime.Remoting.Messaging;
using SDG.UnitTesting.Remoting;

namespace SDG.UnitTesting.Remoting
{
    public class SDGProperty : IContextProperty, IContributeObjectSink 
    {
        private const string _Name = "Red Gate SDG";
        private string _exe;

        public SDGProperty(string exe)
        {
            _exe = exe;
        }

        #region IContributeObjectSink Members

        public IMessageSink GetObjectSink(MarshalByRefObject obj, IMessageSink nextSink)
        {
            return new SDGMessageSink(_exe, nextSink);
        }

        #endregion

        #region IContextProperty Members

        public void Freeze(Context newContext)
        {
        }

        public bool IsNewContextOK(Context newCtx)
        {
            SDGProperty property = newCtx.GetProperty(Name) as SDGProperty;
            if (property == null)
                return false;

            return true;
        }

        public string Name
        {
            get { return _Name; }
        }

        #endregion
    }
}